package com.molin.MethodTest;

public class Demo5Method {
    public static void main(String[] args) {
        int arr[] = {11, 22, 44, 55, 33, 66};
        System.out.println("max num: ");
        System.out.println(getMax(arr));
        System.out.println("max and min:");
        System.out.println(getMaxAndMin(arr)[0]+ " and " +getMaxAndMin(arr)[1]);
    }

    public static int[] getMaxAndMin(int[] arr) {
        int max = arr[0];
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        int maxAndMin[] = {max, min};
        //return语句只能带回一个结果。
        return maxAndMin;
    }

    public static int getMax(int[] arr) {
        int max = arr[0];
        for (int i : arr) {
            if (max < i) {
                max = i;
            }
        }
        return max;
    }
}
